# random模块

import random

# 0-1之间的随机小数
ran = random.random()
print(ran)  # 0.7310712229012095

# 产生整型的1, 3, 5, 7, 9; 左闭右开
ran = random.randrange(1, 10, 2)
print(ran)  # 3

# 都是闭
ran = random.randint(1, 10)
print(ran)  # 8

# 随机选择非空序列
list1 = ['kfx', 'cty', 'zcy', 'kql', 'hs']
ran = random.choice(list1)
print(ran)  # hs

# 打乱顺序
pai = ['红桃A', '红桃8', '方块3', '黑桃6']
random.shuffle(pai)
print(pai)  # ['方块3', '黑桃6', '红桃8', '红桃A']


# 验证码  大写字母与数字的组合

def func():
    code = ''
    for i in range(4):
        ran1 = str(random.randint(0, 9))
        ran2 = str(chr(random.randint(65, 90)))
        ran3 = str(chr(random.randint(97, 122)))

        r = random.choice([ran1, ran2, ran3])
        code += r
    return code


code = func()
print(code)  # wc7p
print(ord('A'))  # 65
print(ord('上'))  # 19978
print(ord('下'))  # 19979
print(chr(19979))  # 下
